package com.atguigu.tingshu.dispatch.config;

import com.atguigu.tingshu.dispatch.properties.XxlJobProperties;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class XXLJobConfiguration {

    @Autowired
    private XxlJobProperties xxlJobProperties ;

    // 配置执行器
    @Bean
    public XxlJobSpringExecutor jobSpringExecutor() {

        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor() ;

        // 设置调度中心访问地址
        xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());

        // 设置调度中心访问令牌
        xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());

        // 设置执行器应用名称
        xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppname());

        // 设置执行器所在服务器的ip地址
        xxlJobSpringExecutor.setIp(xxlJobProperties.getIp());

        // 设置执行器进程所占用的端口号
        xxlJobSpringExecutor.setPort(xxlJobProperties.getPort());

        return xxlJobSpringExecutor ;

    }

}